package com.ruoyi.carpool.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.carpool.domain.WxMessage;
import com.ruoyi.carpool.service.IWxMessageService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 拼车消息Controller
 * 
 * @author ruoyi
 * @date 2022-03-05
 */
@Controller
@RequestMapping("/carpool/message")
public class WxMessageController extends BaseController
{
    private String prefix = "carpool/message";

    @Autowired
    private IWxMessageService wxMessageService;

    @RequiresPermissions("carpool:message:view")
    @GetMapping()
    public String message()
    {
        return prefix + "/message";
    }

    /**
     * 查询拼车消息列表
     */
    @RequiresPermissions("carpool:message:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WxMessage wxMessage)
    {
        startPage();
        List<WxMessage> list = wxMessageService.selectWxMessageList(wxMessage);
        return getDataTable(list);
    }

    /**
     * 导出拼车消息列表
     */
    @RequiresPermissions("carpool:message:export")
    @Log(title = "拼车消息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WxMessage wxMessage)
    {
        List<WxMessage> list = wxMessageService.selectWxMessageList(wxMessage);
        ExcelUtil<WxMessage> util = new ExcelUtil<WxMessage>(WxMessage.class);
        return util.exportExcel(list, "拼车消息数据");
    }

    /**
     * 新增拼车消息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存拼车消息
     */
    @RequiresPermissions("carpool:message:add")
    @Log(title = "拼车消息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WxMessage wxMessage)
    {
        return toAjax(wxMessageService.insertWxMessage(wxMessage));
    }

    /**
     * 修改拼车消息
     */
    @RequiresPermissions("carpool:message:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WxMessage wxMessage = wxMessageService.selectWxMessageById(id);
        mmap.put("wxMessage", wxMessage);
        return prefix + "/edit";
    }

    /**
     * 修改保存拼车消息
     */
    @RequiresPermissions("carpool:message:edit")
    @Log(title = "拼车消息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WxMessage wxMessage)
    {
        return toAjax(wxMessageService.updateWxMessage(wxMessage));
    }

    /**
     * 删除拼车消息
     */
    @RequiresPermissions("carpool:message:remove")
    @Log(title = "拼车消息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wxMessageService.deleteWxMessageByIds(ids));
    }
}
